package cn.zcib.film.service.impl;

import cn.zcib.film.anno.Record;
import cn.zcib.film.bean.Notice;
import cn.zcib.film.bean.vo.NoticeVO;
import cn.zcib.film.mapper.NoticeMapper;
import cn.zcib.film.service.NoticeService;
import cn.zcib.film.util.SystemConstants;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;

@Service
public class NoticeServiceImpl implements NoticeService {
    @Autowired
    private NoticeMapper noticeMapper;
    @Override
    public List<Notice> getList(NoticeVO vo) {
        return noticeMapper.getList(vo);
    }

    @Override
    public int insertNotice(Notice notice) {
        //设置结果行
        int row =0;
//        Notice JSONnotice = JSONObject.parseObject(head, Notice.class);
        //处理字符串，将标题分离出来并封装到Notice
//        Notice notice = new Notice();
//        String[] strings = Pattern.compile("(<(/*)p>)|(<(/*)h[1-6]>)").split(data);
//        if (strings!=null && !Objects.equals(strings, "")){
            //设置标题,第一个元素由于正则分割，所以是空的，第二个元素开始才是文字
//            notice.setTitle(JSONnotice.getTitle());
//            System.out.println("strings[1] = " + strings[1]);
//        }
        //设置正文
        //瑕疵：标题也存在了正文中
//        notice.setContent(JSONnotice.getContent());
        try {
            //尝试设置发布时间
            notice.setPublishTime(new Date());
            //尝试插入
            row = noticeMapper.insertNotice(notice);
        }catch (Exception e){
            e.printStackTrace();
        }
        return row;
    }

    @Override
    public int updateNotice(Notice notice) {
        return noticeMapper.updateNotice(notice);
    }

    @Override
    public int delNotice(Notice notice) {
        return noticeMapper.delNotice(notice);
    }

    @Override
    public List<Notice> listLimit() {
        return noticeMapper.listLimit();
    }
}
